package site.isscloud.web.controller.project;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import site.isscloud.common.annotation.Log;
import site.isscloud.common.core.controller.BaseController;
import site.isscloud.common.core.domain.AjaxResult;
import site.isscloud.common.enums.BusinessType;
import site.isscloud.project.domain.PjLocation;
import site.isscloud.project.service.IPjLocationImportService;
import site.isscloud.project.service.IPjLocationService;
import site.isscloud.common.utils.poi.ExcelUtil;

/**
 * 空间管理Controller
 * 
 * @author junhuang
 * @date 2025-10-14
 */
@RestController
@RequestMapping("/project/location")
public class PjLocationController extends BaseController
{
    @Autowired
    private IPjLocationService pjLocationService;

    @Autowired
    private IPjLocationImportService pjLocationImportService;

    /**
     * 查询空间管理列表
     */
    @PreAuthorize("@ss.hasPermi('project:location:list')")
    @GetMapping("/list")
    public AjaxResult list(PjLocation pjLocation)
    {
        List<PjLocation> list = pjLocationService.selectPjLocationList(pjLocation);
        return success(list);
    }

    /**
     * 导出空间管理列表
     */
    @PreAuthorize("@ss.hasPermi('project:location:export')")
    @Log(title = "空间管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PjLocation pjLocation)
    {
        List<PjLocation> list = pjLocationService.selectPjLocationList(pjLocation);
        ExcelUtil<PjLocation> util = new ExcelUtil<PjLocation>(PjLocation.class);
        util.exportExcel(response, list, "空间管理数据");
    }

    /**
     * 获取空间管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:location:query')")
    @GetMapping(value = "/{lcId}")
    public AjaxResult getInfo(@PathVariable("lcId") Long lcId)
    {
        return success(pjLocationService.selectPjLocationByLcId(lcId));
    }

    /**
     * 新增空间管理
     */
    @PreAuthorize("@ss.hasPermi('project:location:add')")
    @Log(title = "空间管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PjLocation pjLocation)
    {
        return toAjax(pjLocationService.insertPjLocation(pjLocation));
    }

    /**
     * 修改空间管理
     */
    @PreAuthorize("@ss.hasPermi('project:location:edit')")
    @Log(title = "空间管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PjLocation pjLocation)
    {
        return toAjax(pjLocationService.updatePjLocation(pjLocation));
    }

    /**
     * 删除空间管理
     */
    @PreAuthorize("@ss.hasPermi('project:location:remove')")
    @Log(title = "空间管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{lcIds}")
    public AjaxResult remove(@PathVariable Long[] lcIds)
    {
        return toAjax(pjLocationService.deletePjLocationByLcIds(lcIds));
    }

    /**
     * 导入空间管理数据
     */
    @PreAuthorize("@ss.hasPermi('project:location:import')")
    @Log(title = "空间管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<PjLocation> util = new ExcelUtil<PjLocation>(PjLocation.class);
        List<PjLocation> locationList = util.importExcel(file.getInputStream());
        String message = pjLocationImportService.importData(locationList, updateSupport, null);
        return success(message);
    }

    /**
     * 下载导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<PjLocation> util = new ExcelUtil<PjLocation>(PjLocation.class);
        util.importTemplateExcel(response, "空间管理数据");
    }

    /**
     * 修改空间管理米标信息
     */
    @PreAuthorize("@ss.hasPermi('project:location:edit')")
    @Log(title = "空间管理米标", businessType = BusinessType.UPDATE)
    @PutMapping("/marker")
    public AjaxResult editMarker(@RequestBody PjLocation pjLocation)
    {
        return toAjax(pjLocationService.updatePjLocationMarker(pjLocation));
    }
}
